<<<<<<< .mine
:-lib(ic).
:-lib(branch_and_bound).

/*Q5.1*/

techniciens(T):-
	      T = [](5,7,2,6,9,3,7,5,3).

quantite(Q):-
	      Q = [](140,130,60,95,70,85,100,30,45).

benef(B):-
	      B = [](4,5,8,5,6,4,7,10,11).

/*Vecteur de variables*/

fabrique(Fabriquer):-
	      Fabriquer = [](S1,S2,S3,S4,S5,S6,S7,S8,S9),
	      S1 #:: 0..1,
	      S2 #:: 0..1,
	      S3 #:: 0..1,
	      S4 #:: 0..1,
	      S5 #:: 0..1,
	      S6 #:: 0..1,
	      S7 #:: 0..1,
	      S8 #:: 0..1,
	      S9 #:: 0..1.

/*Q5.2*/
nbTotalTech(T,F,N):-
	      dim(F,[Dim]),
	      dim(T,[Dim2]),
	      Dim #= Dim2,
	      ( for(Indice,1,Dim),fromto(0,In,Out,N),param(F,T)
		do
		  V is F[Indice],
		  J is T[Indice],
		  Out #= In + V*J
	      ).

test(F,T,N):-
	      techniciens(T),
	      fabrique(F),
	      nbTotalTech(T,F,N),
	      labeling(F).

/*Résultats
test(F, T, N).

F = [](0, 0, 0, 0, 0, 1, 0, 1, 1)
T = [](5, 7, 2, 6, 9, 3, 7, 5, 3)
N = 11

*/

vectBenefTot(Q,B,V):-
	    dim(Q,[Dim]),
	    dim(B,[Dim2]),
	    Dim #= Dim2,
	    dim(V,[Dim]),
	    ( for(Indice,1,Dim),param(V,Q,B)
	      do
		QteJ is Q[Indice],
		Ben is B[Indice],
		Res is QteJ*Ben,
		Res is V[Indice]
	    ).

test2(Q,B,V):-
	      quantite(Q),
	      benef(B),
	      vectBenefTot(Q,B,V).

/*
Résultats
test2(Q,B,V).

Q = [](140, 130, 60, 95, 70, 85, 100, 30, 45)
B = [](4, 5, 8, 5, 6, 4, 7, 10, 11)
V = [](560, 650, 480, 475, 420, 340, 700, 300, 495)
Yes (0.00s cpu)

*/


/*
V : vecteur des bénéfices totaux
F : vecteur des fabrications
Q : vecteur des quantités
B : vecteur des Bénéf
P : profit total
*/
profitTot(V,F,P):-
	      dim(F,[Dim]),
	      dim(V,[Dim2]),
	      Dim #= Dim2,
	      ( for(Indice,1,Dim),fromto(0,In,Out,P),param(F,V)
		do
		  K is F[Indice],
		  J is V[Indice],
		  Out #= In + K*J
	      ).

test3(V,F,Q,B,P):-
	    fabrique(F),
	    quantite(Q),
	    benef(B),
	    vectBenefTot(Q,B,V),
	    profitTot(V,F,P),
	    labeling(F).

/*
Résultats
test3(V, F, Q, B, P).
(après plusieurs ';')

V = [](560, 650, 480, 475, 420, 340, 700, 300, 495)
F = [](0, 0, 0, 0, 1, 1, 1, 0, 0)
Q = [](140, 130, 60, 95, 70, 85, 100, 30, 45)
B = [](4, 5, 8, 5, 6, 4, 7, 10, 11)
P = 1460

*/

/*Q5.3*/

pose_contraintes(F,NT,P):-
	  fabrique(F),
	  quantite(Q),
	  benef(B),
	  techniciens(T),
	  nbTotalTech(T,F,NT),
	  vectBenefTot(Q,B,V),
	  profitTot(V,F,P),
	  labeling(F).

/*
Résultats

pose_contraintes(F, 22, P).

F = [](0, 0, 0, 0, 1, 1, 1, 0, 1)
P = 1955
Yes (0.00s cpu, solution 1, maybe more) ? ;

F = [](0, 0, 0, 1, 1, 0, 1, 0, 0)
P = 1595
Yes (0.00s cpu, solution 2, maybe more) ? ;

F = [](0, 0, 1, 0, 1, 1, 0, 1, 1)
P = 2035
Yes (0.00s cpu, solution 3, maybe more) ? ;

F = [](0, 0, 1, 1, 1, 0, 0, 1, 0)
P = 1675
Yes (0.00s cpu, solution 4, maybe more) ? ;

F = [](0, 1, 0, 0, 0, 0, 1, 1, 1)
P = 2145
Yes (0.00s cpu, solution 5, maybe more) ? ;

F = [](0, 1, 0, 0, 0, 1, 1, 1, 0)
P = 1990
Yes (0.00s cpu, solution 6, maybe more) ? ;

F = [](0, 1, 0, 0, 1, 1, 0, 0, 1)
P = 1905
Yes (0.00s cpu, solution 7, maybe more) ? ;

F = [](0, 1, 0, 1, 1, 0, 0, 0, 0)
P = 1545
Yes (0.00s cpu, solution 8, maybe more) ? ;

F = [](0, 1, 1, 0, 0, 1, 1, 0, 1)
P = 2665
Yes (0.00s cpu, solution 9, maybe more) ? ;

F = [](0, 1, 1, 1, 0, 0, 1, 0, 0)
P = 2305
Yes (0.00s cpu, solution 10, maybe more) ? ;

F = [](1, 0, 0, 0, 1, 0, 0, 1, 1)
P = 1775
Yes (0.00s cpu, solution 11, maybe more) ? ;

F = [](1, 0, 0, 0, 1, 1, 0, 1, 0)
P = 1620
Yes (0.00s cpu, solution 12, maybe more) ? ;

F = [](1, 0, 0, 1, 0, 1, 0, 1, 1)
P = 2170
Yes (0.00s cpu, solution 13, maybe more) ? ;

F = [](1, 0, 1, 0, 0, 0, 1, 1, 1)
P = 2535
Yes (0.00s cpu, solution 14, maybe more) ? ;

F = [](1, 0, 1, 0, 0, 1, 1, 1, 0)
P = 2380
Yes (0.00s cpu, solution 15, maybe more) ? ;

F = [](1, 0, 1, 0, 1, 1, 0, 0, 1)
P = 2295
Yes (0.00s cpu, solution 16, maybe more) ? ;

F = [](1, 0, 1, 1, 1, 0, 0, 0, 0)
P = 1935
Yes (0.00s cpu, solution 17, maybe more) ? ;

F = [](1, 1, 0, 0, 0, 0, 1, 0, 1)
P = 2405
Yes (0.00s cpu, solution 18, maybe more) ? ;

F = [](1, 1, 0, 0, 0, 1, 1, 0, 0)
P = 2250
Yes (0.00s cpu, solution 19, maybe more) ? ;

F = [](1, 1, 1, 0, 0, 0, 0, 1, 1)
P = 2485
Yes (0.00s cpu, solution 20, maybe more) ? ;

F = [](1, 1, 1, 0, 0, 1, 0, 1, 0)
P = 2330
Yes (0.00s cpu, solution 21, maybe more) ? ;

No (0.00s cpu)

*/

/*Q5.4*/

/*Exemple donné dans l'énoncé*/

p(X,Y,Z,W):-
	      [X,Y,Z,W] #:: [0..10], 
	      X #= Z+Y+2*W, 
	      X #\= Z+Y+W,
	      labeling([X,Y,Z,W]).
	      

minimiser(X,Y,Z,W):-
		minimize( p(X,Y,Z,W) , X ).

/*
labeling sur X :
X = 1
Y = Y{[0, 1]}
Z = Z{[0, 1]}
W = 0
Yes (0.00s cpu)

labeling sur X,Y,Z,W
[eclipse 2]: minimiser(X,Y,Z,W).
lists.eco  loaded in 0.00 seconds
Found a solution with cost 2
Found no solution with cost -1.0Inf .. 1

X = 2
Y = 0
Z = 0
W = 1
Yes (0.00s cpu)
*/
		
optimiser(F,22,P):-
	      Q #= 0-P,
	      minimize(pose_contraintes(F,22,P),Q).

/*
Résultats

optimiser(F, NT, P).
Found a solution with cost -1955
Found a solution with cost -2035
Found a solution with cost -2145
Found a solution with cost -2665
Found no solution with cost -1.0Inf .. -2666

F = [](0, 1, 1, 0, 0, 1, 1, 0, 1)
NT = 22
P = 2665
Yes (0.00s cpu)

*/

/Q5.6 Max : J'ai pas testé...*/
optimiser2(F,22,P):-
	      P #>= 1000,
	      minimize(pose_contraintes(F,N,P),N).



=======
:-lib(ic).

/*Q5.1*/

techniciens(T):-
	      T = [](5,7,2,6,9,3,7,5,3).

quantite(Q):-
	      Q = [](140,130,60,95,70,85,100,30,45).

benef(B):-
	      B = [](4,5,8,5,6,4,7,10,11).

/*Vecteur de variables*/

fabrique(Fabriquer):-
	      Fabriquer = [](S1,S2,S3,S4,S5,S6,S7,S8,S9),
	      S1 #:: 0..1,
	      S2 #:: 0..1,
	      S3 #:: 0..1,
	      S4 #:: 0..1,
	      S5 #:: 0..1,
	      S6 #:: 0..1,
	      S7 #:: 0..1,
	      S8 #:: 0..1,
	      S9 #:: 0..1.

/*Q5.2*/
nbTotalTech(T,F,N):-
	      dim(F,[Dim]),
	      dim(T,[Dim2]),
	      Dim #= Dim2,
	      ( for(Indice,1,Dim),fromto(0,In,Out,N),param(F,T)
		do
		  V is F[Indice],
		  J is T[Indice],
		  rend(V,J,M),
		  Out #= In + M
	      ).

rend(0,J,0).
rend(1,J,J).

test(F,T,N):-
	      techniciens(T),
	      fabrique(F),
	      nbTotalTech(T,F,N),
	      labeling(F).>>>>>>> .r73
